import { useUpdate } from "ahooks";
import clsx from "clsx"
import { useSubscribe } from "../../../framework/common/eventBus";
import { getApproveBtnName } from "../stepUtility";
/**
* 返回扩展节点信息
* 对应原模板 jstemp-negotiate-log
*/
export function NegotiateLogWrap({
    tplData,
    list, 
    consults_unread_ids
}){

    //刷新按钮列表
    let updater = useUpdate();
    useSubscribe("setConsultRead.update", ()=>{
        updater();
    })

    if(tplData){
        list = tplData.NodeInfo.consults;
        consults_unread_ids = tplData.NodeInfo.consults_unread_ids;
    }
    return <ul className="negotiate_log_wrap">
        {
            list.map(function(item, index){
                return ((item.node_type == 7 || item.node_type == 6 || (item.node_type == 2 && item.handle_name) || item.node_type == 12))
                    && <li key={index} className={clsx("log_item", consults_unread_ids.indexOf(item.node_id) != -1 && "unread_tag")}>
                        <div className="log_title">
                            {
                                item.node_type == 7
                                && <p>【{getApproveBtnName({approveType:"Consult", btnText:"协商", tplData: tplData})}】{item.handle_name} {getApproveBtnName({approveType:"Consult", btnText:"协商", tplData: tplData})}给 {item.consult_to_user}</p>
                            }
        
                            {
                                item.node_type == 12
                                && <p>【交办】{item.handle_name} 交办给 {item.assigned_to_user}</p>
                            }
        
                            {
                                item.node_type == 6
                                && <p>【撤回】{item.handle_name}</p>
                            }
                            
                            {
                                item.node_type == 2 && item.handle_name
                                && <p>【{getApproveBtnName({approveType:"ReplyConsult", btnText:"回复协商", tplData: tplData})}】{item.handle_name} {getApproveBtnName({approveType:"ReplyConsult", btnText:"回复协商", tplData: tplData})}给 {item.consult_replay_user}</p>
                            }
        
                            <span>{item.handle_on}</span>
                        </div>
                        {
                            item.handle_name && item.opinion
                            && <pre className="log_content">{item.opinion}</pre>
                        }
                    </li>
            })
        }
    </ul>
 }